package com.hs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.hs.room.model.archive.DevCabinet
import kotlinx.coroutines.flow.Flow

@Dao
interface DevCabinetDao {

    @Insert
    fun insert(d: DevCabinet)

    @Update
    fun update(d: DevCabinet): Int

    @Query("SELECT * FROM dev_cabinet where :name = name")
    fun selectByName(name: String): DevCabinet

    @Query("SELECT * FROM dev_cabinet  WHERE 0=runningIndicator")
    fun getAll(): Flow<List<DevCabinet>>

    @Query("SELECT * FROM dev_cabinet ORDER BY localId LIMIT :limit OFFSET :offset ")
    fun get(limit: Int, offset: Int): Flow<List<DevCabinet>>

    @Query("SELECT * FROM dev_cabinet WHERE 0=runningIndicator ORDER BY localId")
    fun get(): Flow<List<DevCabinet>>

    @Query("SELECT * FROM dev_cabinet WHERE 1=runningIndicator")
    fun getLamp(): Flow<List<DevCabinet>>

    @Query("SELECT name FROM dev_cabinet")
    fun getName(): Flow<List<String>>

    @Query("SELECT count(*) FROM dev_cabinet  WHERE 0=runningIndicator")
    fun count(): Int

    @Delete
    fun delete(d: DevCabinet)

    @Query("SELECT DISTINCT boardId FROM dev_cabinet")
    fun getBoardId(): List<Int>
}